﻿# 
# Registers a set of performance counters 
#

# category names
$SDR_ASR_OBS_CATEGORY = "SDR ASR Observer"
$SDR_WEB_CATEGORY = "SDR Web"

# check if category exists
If ([System.Diagnostics.PerformanceCounterCategory]::Exists($SDR_ASR_OBS_CATEGORY) -eq $False)
{
	# create CounterCreationDataCollection for counters in this category
	$ccdc = New-Object System.Diagnostics.CounterCreationDataCollection

	# prepare list of performance counters to create
	$OBS_FINISHED_TASKS_COUNTER = "Finished ASR Tasks"
	$OBS_FAILED_TASKS_COUNTER = "Failed ASR Tasks"
	$OBS_DISPOSED_TASKS_COUNTER = "Disposed ASR Tasks"
	$OBS_INSERTED_TOKENS_COUNTER = "Inserted Tokens"
	$OBS_CHECK_STATUS_TIMING_COUNTER = "Check Time"
	
	# prepare counter creation data
	$obsFinishedTasksCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $OBS_FINISHED_TASKS_COUNTER, $OBS_FINISHED_TASKS_COUNTER, NumberOfItems64
	$obsFailedTasksCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $OBS_FAILED_TASKS_COUNTER, $OBS_FAILED_TASKS_COUNTER, NumberOfItems64
	$obsDisposedTasksCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $OBS_DISPOSED_TASKS_COUNTER, $OBS_DISPOSED_TASKS_COUNTER, NumberOfItems64
	$obsInsertedTokensCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $OBS_INSERTED_TOKENS_COUNTER, $OBS_INSERTED_TOKENS_COUNTER, NumberOfItems64
	$obsCheckStatusTimingCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $OBS_CHECK_STATUS_TIMING_COUNTER, $OBS_CHECK_STATUS_TIMING_COUNTER, NumberOfItems64
	
	# add counter creation data to the collection
	$ccdc.Add($obsFinishedTasksCcd)
	$ccdc.Add($obsFailedTasksCcd)
	$ccdc.Add($obsDisposedTasksCcd)
	$ccdc.Add($obsInsertedTokensCcd)
	$ccdc.Add($obsCheckStatusTimingCcd)
	
	# create category
	[System.Diagnostics.PerformanceCounterCategory]::Create($SDR_ASR_OBS_CATEGORY, $SDR_ASR_OBS_CATEGORY, $ccdc)
}

# check if SDR Web category exists
If ([System.Diagnostics.PerformanceCounterCategory]::Exists($SDR_WEB_CATEGORY) -eq $False)
{
	# create CounterCreationDataCollection for counters in this category
	$ccdc = New-Object System.Diagnostics.CounterCreationDataCollection

	# prepare list of performance counters to create
	$WEB_NUMBER_OF_REQUESTS_COUNTER = "Number of requests"
	$WEB_AVG_RESPONSE_TIME_COUNTER = "Average response time"
	$WEB_AVG_REQUEST_SIZE_COUNTER = "Average request size"
	$WEB_AVG_RESPONSE_SIZE_COUNTER = "Average response size"
	
	# prepare counter creation data
	$webNumberOfRequestsCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $WEB_NUMBER_OF_REQUESTS_COUNTER, $WEB_NUMBER_OF_REQUESTS_COUNTER, NumberOfItems64
	$webAvgResponseTimeCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $WEB_AVG_RESPONSE_TIME_COUNTER, $WEB_AVG_RESPONSE_TIME_COUNTER, NumberOfItems64
	$webAvgRequestSizeCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $WEB_AVG_REQUEST_SIZE_COUNTER, $WEB_AVG_REQUEST_SIZE_COUNTER, NumberOfItems64
	$wevavgResponseSizeCcd = New-Object System.Diagnostics.CounterCreationData -ArgumentList $WEB_AVG_RESPONSE_SIZE_COUNTER, $WEB_AVG_RESPONSE_SIZE_COUNTER, NumberOfItems64
	
	# add counter creation data to the collection
	$ccdc.Add($webNumberOfRequestsCcd)
	$ccdc.Add($webAvgResponseTimeCcd)
	$ccdc.Add($webAvgRequestSizeCcd)
	$ccdc.Add($wevavgResponseSizeCcd)
	
	# create category
	[System.Diagnostics.PerformanceCounterCategory]::Create($SDR_WEB_CATEGORY, $SDR_WEB_CATEGORY, $ccdc)
}